/**
 * 首页组件。
 *
 * 该组件渲染一个包含图表的页面。图表使用Echarts库绘制，展示了不同渠道的访问量。
 * 它通过定义并使用Echarts的配置选项来定制图表的外观和行为。
 */
import { useEcharts } from "./useEcharts";
import { useState, useEffect } from "react";
import "./index.less";
function Index() {
	let data = useState<string[]>([]);
	useEffect(() => {
		data = [
			{
				name: "Email",
				type: "line",
				stack: "Total",
				showSymbol: false,
				smooth: true,
				data: [120, 132, 101, 134, 90, 230, 210]
			},
			{
				name: "Union Ads",
				type: "line",
				stack: "Total",
				showSymbol: false,
				smooth: true,
				data: [220, 182, 191, 234, 290, 330, 310]
			},
			{
				name: "Video Ads",
				type: "line",
				smooth: true,
				showSymbol: false,
				stack: "Total",
				data: [150, 232, 201, 154, 190, 330, 410]
			}
		];
	}, []);
	// 定义Echarts图表的配置选项
	let option = {
		tooltip: {
			trigger: "axis"
		},
		legend: {
			icon: "circle",
			data: ["Email", "Union Ads", "Video Ads", "Direct", "Search Engine"]
		},
		grid: {
			left: "3%",
			right: "4%",
			bottom: "3%",
			containLabel: true
		},
		xAxis: {
			type: "category",
			boundaryGap: false,
			data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
		},
		yAxis: {
			type: "value"
		},
		series: [
			{
				name: "Email",
				type: "line",
				stack: "Total",
				showSymbol: false,
				smooth: true,
				data: [120, 132, 101, 134, 90, 230, 210]
			},
			{
				name: "Union Ads",
				type: "line",
				stack: "Total",
				showSymbol: false,
				smooth: true,
				data: [220, 182, 191, 234, 290, 330, 310]
			},
			{
				name: "Video Ads",
				type: "line",
				smooth: true,
				showSymbol: false,
				stack: "Total",
				data: [150, 232, 201, 154, 190, 330, 410]
			}
		]
	};

	// 返回图表容器组件
	const [echartsRef] = useEcharts(option, data);
	return <div ref={echartsRef} className="box"></div>;
}

export default Index;
